#include "DataStruct.fxh"
#include "States.fxh"

float4x4 mWorld;                  // World matrix for object
//float4x4 mWorldView;              // Wold * View matrix
float4x4 mViewProjection;    // World * View * Projection matrix
float4   vAmbientColor;		 //abmient
float4   vDiffuseColor;      //diffuse
float4   vSpecularColor;     //Specular
float    fSpecularPower;     //Specular Power
Texture2D texDiffuse;         //Diffuse texture for mesh
bool     bTexture;            //boolean for using texture or not
//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT_POSNORMTEXTANG RenderStaticMesh_PosNormUvTangVS( VS_INPUT_VERTNORMTEXTANG inVert )
{
    VS_OUTPUT_POSNORMTEXTANG Output;
	     
    // Transform the position from object space to homogeneous projection space
	// Be careful!!! use float4 although the input is float3!!!
	Output.PosWorld = mul(float4(inVert.Pos,1.0), mWorld).xyz;
	Output.Position = mul(float4(Output.PosWorld,1.0), mViewProjection);
	Output.TextureUV = inVert.TextureUV;
	Output.NormWorld = normalize(mul(inVert.Normal,(float3x3)mWorld));
	Output.TangWorld = normalize(mul(inVert.Tangent, (float3x3)mWorld));
	Output.BiNormWorld = normalize(mul(inVert.Binormal, (float3x3)mWorld));   
    return Output;    
}

float4 RenderStaticMesh_PosNormUvTangPS( VS_OUTPUT_POSNORMTEXTANG In ):SV_TARGET
{
	return float4(In.NormWorld,1.0f);
}


//--------------------------------------------------------------------------------------
// Renders scene 
//--------------------------------------------------------------------------------------
technique11 RenderStaticMesh_PosNormUvTang
{
    pass P0
    {        
		SetRasterizerState(RenderMesh_RS);  
        SetVertexShader(CompileShader(vs_5_0, RenderStaticMesh_PosNormUvTangVS()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, RenderStaticMesh_PosNormUvTangPS())); 
    }
}


//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT_POSNORMTEX RenderStaticMesh_PosNormUvVS( VS_INPUT_VERTNORMTEX inVert )
{
    VS_OUTPUT_POSNORMTEX Output;
	     
    // Transform the position from object space to homogeneous projection space
	// Be careful!!! use float4 although the input is float3!!!
	Output.PosWorld = mul(float4(inVert.Pos,1.0), mWorld).xyz;
	Output.Position = mul(float4(Output.PosWorld,1.0), mViewProjection);
	Output.TextureUV = inVert.TextureUV;
	Output.NormWorld = normalize(mul(inVert.Normal,(float3x3)mWorld));	
    return Output;    
}

float4 RenderStaticMesh_PosNormUvPS( VS_OUTPUT_POSNORMTEX In ):SV_TARGET
{
	//return float4(In.NormWorld,1.0f);
	if(bTexture)
		return texDiffuse.Sample(LinearSampler,In.TextureUV);
	else
		return vDiffuseColor;
}


//--------------------------------------------------------------------------------------
// Renders scene 
//--------------------------------------------------------------------------------------
technique11 RenderStaticMesh_PosNormUv
{
    pass P0
    {        
		SetRasterizerState(RenderMesh_RS);  
        SetVertexShader(CompileShader(vs_5_0, RenderStaticMesh_PosNormUvVS()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, RenderStaticMesh_PosNormUvPS())); 
    }
}
